package com.mybatisplus.service.impl;

import com.mybatisplus.entity.BaseResultBean;
import com.mybatisplus.entity.Teacher;
import com.mybatisplus.mapper.TeacherMapper;
import com.mybatisplus.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
 * Auto created By IntelliJ IDEA
 *
 * @author : gzrong
 * @Date : 2023/5/7 13:23
 */
@Service
public class TeacherServiceImpl implements TeacherService {
    @Autowired
    TeacherMapper teacherMapper;

    @Override
    public BaseResultBean alterPassword(String stuid, String newPassword, HttpServletRequest request) {
        BaseResultBean resultBean = new BaseResultBean();
        teacherMapper.updatePasswordByStuid(stuid, newPassword);
        request.getSession().invalidate();
        resultBean.setMessage("密码更改成功，请使用新密码登录");
        resultBean.setStatus(true);
        return resultBean;
    }

    @Override
    public Teacher selectTeacherById(String stuid) {
        return teacherMapper.getTeacherByID(stuid);
    }

    @Override
    public String getTeacherName(String stuid) {
        return teacherMapper.getTeacherNameByTeacherID(stuid);
    }
}
